//
// Created by zxm on 18-10-10.
//
#include <iostream>
#include <string>

#include "serial.h"

using namespace std;

uint8_t test_data[]="test_data";
uint8_t read_buffer[256];

int main(int argc, char **argv)
{
    if (argc != 2)
    {
        cout << "Please give a serial name!" << endl;
        cout << "For example: ./seiral_test /dev/ttyUSB0" << endl;
        return -1;
    }

    string serial_name = argv[1];
    Serial serial;

    if (serial.Open(serial_name.c_str(), 9600, 8, EVEN, 1) == 0)
    {
        for (auto i = 0; i < 10; i++)
            serial.Write(test_data,10);
    }

    // len: the length of read data
    auto len = serial.Read(read_buffer);

    serial.Close();
}